package com.xayy.health.mgt.controller;

import cn.kawins.base.result.ResultBody;
import cn.kawins.mybatis.base.BaseController;
import com.xayy.health.core.config.datasource.DatasourceHolder;
import com.xayy.health.mgt.model.TestLindorm;
import com.xayy.health.mgt.model.vo.TaskFaultPredictDataVo;
import com.xayy.health.mgt.service.DiagnoseService;
import com.xayy.health.mgt.service.TestLindormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author dongxingli
 * createTime 2023/9/26
 * @version V1.0
 */
@RestController
@RequestMapping(value = "/lindrom")
@Api(tags = "测试Lindorm数据库接口")
public class TestLindormController extends BaseController<TestLindorm> {

    @Autowired
    TestLindormService testLindormService;

    @Autowired
    private DiagnoseService diagnoseService;


    @GetMapping("test")
    @ApiOperation(value = "getTaskFaultPredictDataList方法测试")
    public ResultBody test() {
        DatasourceHolder.changeSource("clickhouse");
        TaskFaultPredictDataVo taskFaultPredictDataVo=new TaskFaultPredictDataVo();
        taskFaultPredictDataVo.setIsCaseOne(0);
        taskFaultPredictDataVo.setTaskChildId(1745369934344486912L);
        String[] arr=new String[]{"ZK38"};
        taskFaultPredictDataVo.setParamCodes(arr);
        return ResultBody.success(diagnoseService.getTaskFaultPredictDataList(taskFaultPredictDataVo));
    }


    /**
     * 查
     *
     * @return ResultBody
     */
    @GetMapping("select")
    @ApiOperation(value = "查")
    public ResultBody select() {
        DatasourceHolder.changeSource("clickhouse");
        return ResultBody.success(testLindormService.selectAll());
    }

    /**
     * 导入sql脚本
     * @param sqlPath sql文件路径
     * @return ResultBody
     */
    @GetMapping("importData")
    @ApiOperation(value = "导入sql脚本")
    public ResultBody importData(@RequestParam("sql文件路径") String sqlPath) {
        DatasourceHolder.changeSource("clickhouse");
        return ResultBody.checkResult(testLindormService.importData(sqlPath));
    }

    /**
     * 增
     * @param testLindorm lindorm入参
     * @return ResultBody
     */
    @PostMapping("add")
    @ApiOperation(value = "增")
    public ResultBody add(@RequestBody TestLindorm testLindorm) {
        DatasourceHolder.changeSource("clickhouse");
        return ResultBody.success(testLindormService.insert(testLindorm));
    }

    /**
     * 改
     * @param testLindorm lindorm入参
     * @return ResultBody
     */
    @PutMapping("update")
    @ApiOperation(value = "改")
    public ResultBody update(@RequestBody TestLindorm testLindorm) {
        DatasourceHolder.changeSource("clickhouse");
        return ResultBody.success(testLindormService.updateById(testLindorm));
    }

    /**
     * 删
     * @param id 入参
     * @return ResultBody
     */
    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "删")
    public ResultBody delete(@PathVariable String id) {
        DatasourceHolder.changeSource("clickhouse");
        return ResultBody.success(testLindormService.deleteById(id));
    }

    /**
     * 清除Mysql数据
     * @return ResultBody
     */
    @GetMapping("truncateMysql")
    @ApiOperation(value = "清除Mysql数据")
    public ResultBody delete() {
        return ResultBody.success(testLindormService.truncateMysql());
    }


    /**
     * 清除Hologres数据
     * @return ResultBody
     */
    @GetMapping("cleanHologres")
    @ApiOperation(value = "清除Hologres数据")
    public ResultBody cleanHologres() {
        return ResultBody.success(testLindormService.cleanHologres());
    }


    /**
     * 清除mysql数据根据表名
     * @param tableName 表名
     * @return ResultBody
     */
    @GetMapping("truncateMysqlByTableName/{tableName}")
    @ApiOperation(value = "清除mysql数据根据表名")
    public ResultBody truncateMysqlByTableName(@ApiParam("mysql表名") @PathVariable String tableName) {
        return ResultBody.success(testLindormService.truncateMysqlByTableName(tableName));
    }
}
